#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;


/**
 * @brief 49. 字母异位词分组
 * https://leetcode.cn/problems/group-anagrams/
 */
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> table;

        for (string& s : strs) {
            string tmpS(s);
            sort(tmpS.begin(), tmpS.end());
            table[tmpS].emplace_back(s);
        }

        vector<vector<string>> res;
        for (auto& [s, ss] : table) res.emplace_back(ss);

        return res;
    }
};
